﻿Imports MICROFORMA.BEL
Imports MICROFORMA.DIL
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports System.Data.Common
Imports System.Data

Public Class PermisoDA
    Implements PermisoDI

    Public Function List() As PermisoBECollection Implements DIL.PermisoDI.List

        Dim dr As DbDataReader = Nothing

        Dim o_BECollec_Permiso_BE As New PermisoBECollection

        Dim o_Permiso_BE As PermisoBE

        Dim db As Database = DatabaseFactory.CreateDatabase()

        Dim query As String = "select * from Permiso where estado=0"

        Dim dbCommand As DbCommand = db.GetSqlStringCommand(query)

        dr = db.ExecuteReader(dbCommand)

        While dr.Read()
            o_Permiso_BE = New PermisoBE
            o_Permiso_BE.IdPermiso = dr("IdPermiso")
            o_Permiso_BE.Nombre = dr("Nombre")
            o_Permiso_BE.FechaCreacion = dr("FechaCreacion")
            o_Permiso_BE.FechaModificacion = dr("FechaModificacion")
            o_Permiso_BE.Estado = dr("Estado")

            o_BECollec_Permiso_BE.Add(o_Permiso_BE)
            o_Permiso_BE = Nothing
        End While

        Return o_BECollec_Permiso_BE

    End Function

    Public Function GetList(ByVal _idRol As Int16) As DataTable Implements DIL.PermisoDI.GetList

        Dim db As Database = DatabaseFactory.CreateDatabase()

        Dim query As String = "select Permiso.*,RolOpcion.IdPermiso as bolPermiso from Permiso left outer join RolOpcion " & _
                              "on    Permiso.IdPermiso = RolOpcion.IdPermiso and  RolOpcion.IdRol= " & _idRol

        Dim dbCommand As DbCommand = db.GetSqlStringCommand(query)

        Dim productsDataSet As DataSet = Nothing

        productsDataSet = db.ExecuteDataSet(dbCommand)


        Return productsDataSet.Tables(0)

    End Function



    

End Class
